package com.protocols.sctp.m3ua.sccp.tcap.camel;

import java.io.Serializable;

import com.protocols.BCDNumber;
import com.protocols.GeneralProtocolData;
import com.protocols.OctaveInteger;
import com.protocols.ProtoOperations;
import com.protocols.ProtocolStackException;
import com.protocols.sctp.m3ua.sccp.tcap.TcapBegin;
import com.protocols.sctp.m3ua.sccp.tcap.TcapConstructor;
import com.protocols.sctp.m3ua.sccp.tcap.TcapPrimitiveUnitByteArray;
import com.protocols.sctp.m3ua.sccp.tcap.TcapPrimitiveUnitNumber;

public class BCSMEvent implements GeneralProtocolData{

	private TcapConstructor BCSMEvent = new TcapConstructor(0x30);
	private TcapPrimitiveUnitNumber EventTypeBCSM = new TcapPrimitiveUnitNumber(0x80);
	private TcapPrimitiveUnitNumber MonitorMode = new TcapPrimitiveUnitNumber(0x81);
	private TcapConstructor LegIDContainer = new TcapConstructor(0xa2);
	private TcapPrimitiveUnitNumber SendingSideID = new TcapPrimitiveUnitNumber(0x80);		
	private TcapPrimitiveUnitNumber ReceivingSideID = new TcapPrimitiveUnitNumber(0x81);	
	private TcapConstructor DPSpecificationCriteria = new TcapConstructor(0xbe);
	private TcapPrimitiveUnitNumber ApplicationTimer = new TcapPrimitiveUnitNumber(0x81);
	
	// Sending Side is All Ways the IN
	// Receiving Side is All Ways the the MSC
	//Leg ID1 = Originator
	//Leg ID2= Terminating Party
	
	
	public BCSMEvent(){
		BCSMEvent.addElement(EventTypeBCSM);
		BCSMEvent.addElement(MonitorMode);
		BCSMEvent.addElement(LegIDContainer);
		LegIDContainer.addElement(SendingSideID);
		LegIDContainer.addElement(ReceivingSideID);
		BCSMEvent.addElement(DPSpecificationCriteria);
		DPSpecificationCriteria.addElement(ApplicationTimer);
	}

	public void setBCSMEvent(int eventtype, int monitormode){
		EventTypeBCSM.setTagValue(eventtype);
		MonitorMode.setTagValue(monitormode);
		
	}
	
	public long getEventType(){
		return EventTypeBCSM.getTagValue();
	}
	
	public long getMonitorMode(){
		return MonitorMode.getTagValue();
	}
	
	public void setLegId(Boolean sendingside, int legid){
		if(sendingside){
			SendingSideID.setTagValue(legid);
			ReceivingSideID.setVisible(false);
		}
		else{
			ReceivingSideID.setTagValue(legid);
			SendingSideID.setVisible(false);
		}
		
	}
	public int getLegType(){
		
		if (SendingSideID.isVisible())
			return 1;
		else if (ReceivingSideID.isVisible())
			return 2;
		else 
			return 0;
	}
	
	public void getLegId(){
		if(getLegType()==1){
			SendingSideID.getTagValue();			
		}
		else 
			ReceivingSideID.getTagValue();			
		
		
	}
	
	public void setApplicationTimer(int appclicationtimer){
		ApplicationTimer.setTagValue(appclicationtimer);
	}
	
	public long getApplicationTimer(){
		return ApplicationTimer.getTagValue();
	}
	
	public TcapConstructor getRootComponent(){
		return BCSMEvent;
	}
	
	@Override
	public byte[] getByteArray() {
		// TODO Auto-generated method stub
		return BCSMEvent.getByteArray();
	}

	@Override
	public int getLength() {
		// TODO Auto-generated method stub
		return getByteArray().length;
	}

	@Override
	public byte[] decode(byte[] input) throws ProtocolStackException {
		// TODO Auto-generated method stub
		return BCSMEvent.decode(input);
	}
}
